package com.pierfrancescosoffritti.androidyoutubeplayer.core.sampleapp.examples.viewPagerExample;

import android.os.Bundle;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentStatePagerAdapter;
import androidx.viewpager.widget.PagerAdapter;
import androidx.viewpager.widget.ViewPager;

import com.pierfrancescosoffritti.aytplayersample.R;

public class ViewPagerActivity extends AppCompatActivity {

  private static final int NUM_PAGES = 5;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_view_pager_example);

    ViewPager viewPager = findViewById(R.id.view_pager);
    PagerAdapter viewPagerAdapter = new ViewPagerAdapter(getSupportFragmentManager());
    viewPager.setAdapter(viewPagerAdapter);
  }

  private class ViewPagerAdapter extends FragmentStatePagerAdapter {
    ViewPagerAdapter(FragmentManager fm) {
      super(fm);
    }

    @Override
    public Fragment getItem(int position) {
      return new ViewPagerFragment();
    }

    @Override
    public int getCount() {
      return NUM_PAGES;
    }

    @Override
    public CharSequence getPageTitle(int position) {
      return "Page " + position;
    }
  }
}
